package GUI;

import java.awt.event.*;

import javax.swing.*;

public class PN_Pointer_Panel extends JPanel {
	private static final long serialVersionUID = -2315876257874083780L;
	
	private PN_Draw_Panel drawPanel;
	JRadioButton Select;
	JRadioButton Place;
	JRadioButton Transition;
	JRadioButton Arc;
	JRadioButton Token;
	JRadioButton Eraser;
	JButton CleanAll;
	
	public PN_Pointer_Panel(PN_Draw_Panel dp) {
		this.setBorder(BorderFactory.createTitledBorder("Pointer Type"));
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.drawPanel = dp;
		
		ButtonGroup selGroup = new ButtonGroup();
		Select = new JRadioButton("Select");
		Place = new JRadioButton("Place");
		Transition = new JRadioButton("Transition");
		Arc = new JRadioButton("Arc");
		Token = new JRadioButton("Add Tokens");
		Eraser = new JRadioButton("Eraser");
		CleanAll = new JButton("Clean All");
		selGroup.add(Select);
		selGroup.add(Place);
		selGroup.add(Transition);
		selGroup.add(Arc);
		selGroup.add(Token);
		selGroup.add(Eraser);
		Select.setSelected(true);
		this.add(Select);
		this.add(Place);
		this.add(Transition);
		this.add(Arc);
		this.add(Token);
		this.add(Eraser);
		this.add(CleanAll);
		
		ActionListener SelAL = new SelAL(),
			PlaceAL = new PlaceAL(),
			TransAL = new TransAL(),
			ArcAL = new ArcAL(),
			TokenAL = new TokenAL(),
			EraseAL = new EraseAL();
		Select.addActionListener(SelAL);
		Place.addActionListener(PlaceAL);
		Transition.addActionListener(TransAL);
		Arc.addActionListener(ArcAL);
		Token.addActionListener(TokenAL);
		Eraser.addActionListener(EraseAL);
		CleanAll.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
//				System.out.println("Clean All Clicked");
				drawPanel.CleanAllElement();
			}
		});

	}
	
	class SelAL implements ActionListener {
		public void actionPerformed(ActionEvent e){
			JRadioButton selected = (JRadioButton)(e.getSource());
			if (selected.isSelected() && selected==Select)
					drawPanel.SetDrawState(PN_Draw_Panel.DS_SELECT);
		}
	}
	class PlaceAL implements ActionListener {
		public void actionPerformed(ActionEvent e){
			JRadioButton selected = (JRadioButton)(e.getSource());
			if (selected.isSelected() && selected==Place)
					drawPanel.SetDrawState(PN_Draw_Panel.DS_PLACE);
		}
	}
	class TransAL implements ActionListener {
		public void actionPerformed(ActionEvent e){
			JRadioButton selected = (JRadioButton)(e.getSource());
			if (selected.isSelected() && selected==Transition)
					drawPanel.SetDrawState(PN_Draw_Panel.DS_TRANSITION);
		}
	}
	class ArcAL implements ActionListener {
		public void actionPerformed(ActionEvent e){
			JRadioButton selected = (JRadioButton)(e.getSource());
			if (selected.isSelected() && selected==Arc)
					drawPanel.SetDrawState(PN_Draw_Panel.DS_ARC);
		}
	}
	class TokenAL implements ActionListener {
		public void actionPerformed(ActionEvent e){
			JRadioButton selected = (JRadioButton)(e.getSource());
			if (selected.isSelected() && selected==Token)
					drawPanel.SetDrawState(PN_Draw_Panel.DS_TOKEN);
		}
	}
	class EraseAL implements ActionListener {
		public void actionPerformed(ActionEvent e){
			JRadioButton selected = (JRadioButton)(e.getSource());
			if (selected.isSelected() && selected==Eraser)
					drawPanel.SetDrawState(PN_Draw_Panel.DS_ERASER);
		}
	}
}
